do "...\First.do"

********************************************************************************
* LMDB - Medication
********************************************************************************


clear 
use "$raw\lmdb_moreyears.dta"


g ATC3=substr(atc,1,3)
g ATC5=substr(atc,1,5)

g statins=(ATC5=="C10AA")
g ACE=(ATC3=="C09")
g metformin=(ATC3=="A10")
g COPD_med=(inlist(ATC5, "R03AC", "R03CC", "R03BB"))

g year=year(eksd)

sort pnr eksd


keep if statins==1 | ACE==1 | metformin==1 | COPD_med==1
collapse (max) statins ACE metformin COPD_med, by(pnr year)

save "$work\lmdb_new_types.dta", replace



